package cn.yunhe.serves;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.yunhe.dao.AdminDao;
import cn.yunhe.entity.Admin;
import cn.yunhe.factory.SqlSessionFactoryUtil;

public class AdminServes {
	SqlSession sqlSession=null;
	public Admin adminLogin(String adminname,String adminpass){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		AdminDao adminDao =sqlSession.getMapper(AdminDao.class);
		Admin admin = adminDao.adminLogin(adminname, adminpass);
		return admin;
	}
	
	public boolean adminRegist(String adminname,String adminpass){
			sqlSession=SqlSessionFactoryUtil.getSqlSession();
			AdminDao adminDao=sqlSession.getMapper(AdminDao.class);
			boolean flag=adminDao.adminRegist(adminname, adminpass);
			sqlSession.commit();	
		    return flag;	
	}
	
	public List<Admin> selectAllAdmin(){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		AdminDao adminDao=sqlSession.getMapper(AdminDao.class);
		List<Admin> list=adminDao.selectAllAdmin();
		return list;
	}
	
	public boolean deleteAdmin(int adminid){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		AdminDao adminDao=sqlSession.getMapper(AdminDao.class);
		boolean flag=adminDao.deleteAdmin(adminid);
		sqlSession.commit();
		return flag;
	}
	
}
